package login.controller;

import login.User;
import org.springframework.stereotype.Controller;
import org.springframework.validation.Errors;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.RequestMapping;
import service.Increase;

import javax.annotation.Resource;
import javax.validation.Valid;

@Controller
public class RegisterController {
    @Resource(name="Increase")
    Increase Increase;
    @RequestMapping("/reg")
    public String registerUser(@Valid User user, Errors errors) {
        if (errors.getErrorCount() > 0) {
            for (FieldError error : errors.getFieldErrors()) {
                System.out.println(error.getField() + ":" + error.getDefaultMessage());//调试信息，可看到错误信息
            }
            return "forward:/register.jsp";
        } else if (Increase.execute(user)){
            return "register_succ";
        }else {
            return "forward:/register.jsp";
        }
    }
    @RequestMapping("/changeLocale")
    public String changeLocale(){
        return "forward:/register.jsp";
    }
    public Increase getIncrease() {
        return Increase;
    }

    public void setIncrease(Increase Increase) {
        this.Increase = Increase;
    }

}
